package followme.yaohuile.com.followme.parsejson.recommend;

import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;

import com.alibaba.fastjson.JSON;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;

import org.json.JSONException;
import org.json.JSONObject;

import followme.yaohuile.com.followme.bean.recommend.ListData;
import followme.yaohuile.com.followme.network.recommend.NetWork;
import followme.yaohuile.com.followme.utils.LogUtils;


/**
 * Created by Administrator on 15-11-14.
 */
public class ParserRecommendListView {
    public static void getData(String url, final Handler handler){
        if(!TextUtils.isEmpty(url)){
            NetWork.getNetData(url, new RequestCallBack<String>() {
                @Override
                public void onSuccess(ResponseInfo<String> responseInfo) {
                    String json = responseInfo.result;
                    Log.d("main","热门json=" + json);
                    try {
                        JSONObject object = new JSONObject(json);
                        ListData listData = JSON.parseObject(object.toString(), ListData.class);
                        Message message = new Message();
                        message.what = 0x124;
                        message.obj = listData;
                        handler.sendMessage(message);
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }

                }

                @Override
                public void onFailure(HttpException e, String s) {
                    LogUtils.LOG_D(getClass(), "网络访问失败");
                }
            });
        }
    }
}
